package com.zzh.partnersys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zzh.partnersys.entity.UserTeamDO;
import com.zzh.partnersys.mapper.UserTeamMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzh.partnersys.service.UserTeamService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author zzh
 * @since 2024-07-20
 */
@Service
public class UserTeamServiceImpl extends ServiceImpl<UserTeamMapper, UserTeamDO> implements UserTeamService {

    // 查询指定团队的用户ID列表（不包含已删除的关系）
    @Override
    public Set<Long> selectTeamUserIdList(Long teamId) {
        if (teamId == null || teamId <= 0){
            return null;
        }
        // 只查询未删除的用户队伍关系
        List<UserTeamDO> userTeamDOS = baseMapper.selectList(
                new LambdaQueryWrapper<UserTeamDO>()
                        .eq(UserTeamDO::getTeamId, teamId)
                        .eq(UserTeamDO::getIsDelete, 0)  // 只查询未删除的关系
                        .select(UserTeamDO::getUserId)
        );
        return userTeamDOS.stream().map(UserTeamDO::getUserId).collect(Collectors.toSet());
    }
}
